package com.xwtec.iterator.v1;

/**
 * @Author: zt
 * @Date: 2021/3/4 21:23
 */
public class Main {
    public static void main(String[] args) {
        ArrayList_ arrayList_ = new ArrayList_();
        for (int i = 0; i <15 ; i++) {
            arrayList_.add("hello");

        }
        System.out.println(arrayList_.index);
    }
}


/**
 * 模拟一个arrayList的容器
 */
class ArrayList_{

    Object[] objects = new Object[10];
    int index = 0;

    public void add(Object o){
        if(index == objects.length){
            Object[] newObject = new Object[objects.length*2];
            System.arraycopy(objects,0,newObject,0,objects.length);
            objects = newObject;
        }
        objects[index]= o;
        index++;
    }

    public int getSize(){
        return index;
    }

}